import { Injectable } from '@nestjs/common';
import PhotoEntity from './photo.entity';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';

@Injectable()
export class PhotoService {
  constructor(
    @InjectRepository(PhotoEntity)
    private readonly appPhotoRepository: Repository<PhotoEntity>,
  ) {}

  createPhoto = async () => {
    const photo = new PhotoEntity();
    photo.description = '测试数据';
    photo.filename = 'header';
    photo.name = '张三';
    photo.views = 100;

    return this.appPhotoRepository
      .save(photo)
      .then(res => {
        return res;
      })
      .catch(err => {
        return err;
      });
  };
}
